﻿#!/usr/bin/env python
# -*- coding:utf-8 -*-

import unittest
from appium import webdriver
from UiManager.utils.initialize import screen

__author__ = 'wiggins'


class MyUnittestTestCase(unittest.TestCase):
    outputs_dict = {}

    def __init__(self, method_name='runTest', case=None, base_url='localhost', port=4723, capabilities=None, log=None):
        super(MyUnittestTestCase, self).__init__(method_name)
        self.base_url = base_url
        self.capabilities = capabilities
        self.case = case
        self.port = str(port)
        self.log = log

    # 断言
    def assert_result(self, response_to_check):
        pass

    # 提取服务器返回内容
    def extrator(self, extrator_type, extrator,response_to_check=''):
        pass

    # 保存从服务器返回中提取的内容
    def save_result(self, response_to_check):
        pass

    def setUp(self):
        self.log.info('启动setUp方法')
        try:
            self.driver = webdriver.Remote('http://' + self.base_url + ':' + self.port + '/wd/hub', self.capabilities)
        except Exception as e:
            self.log.error(e)

    def tearDown(self):
        try:
            # 保存截图
            self.outputs_dict['image'] = screen(driver=self.driver)
            self.log.info('保存截图，%s' % self.outputs_dict['image'])
            self.log.info('执行tearDown方法')
            self.driver.quit()
        except Exception as e:
            self.log.error(e)


